package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BkFriendship;
import com.ruoyi.system.service.IBkFriendshipService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 友链信息Controller
 * 
 * @author ruoyi
 * @date 2025-01-11
 */
@RestController
@RequestMapping("/bk/friendship")
public class BkFriendshipController extends BaseController
{
    @Autowired
    private IBkFriendshipService bkFriendshipService;

    /**
     * 查询友链信息列表
     */
//    @PreAuthorize("@ss.hasPermi('bk:friendship:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(BkFriendship bkFriendship)
    {
        startPage();
        List<BkFriendship> list = bkFriendshipService.selectBkFriendshipList(bkFriendship);
        return getDataTable(list);
    }

    /**
     * 导出友链信息列表
     */
    @PreAuthorize("@ss.hasPermi('bk:friendship:export')")
    @Log(title = "友链信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BkFriendship bkFriendship)
    {
        List<BkFriendship> list = bkFriendshipService.selectBkFriendshipList(bkFriendship);
        ExcelUtil<BkFriendship> util = new ExcelUtil<BkFriendship>(BkFriendship.class);
        util.exportExcel(response, list, "友链信息数据");
    }

    /**
     * 获取友链信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('bk:friendship:query')")
    @GetMapping(value = "/{friendshipId}")
    public AjaxResult getInfo(@PathVariable("friendshipId") Long friendshipId)
    {
        return success(bkFriendshipService.selectBkFriendshipByFriendshipId(friendshipId));
    }

    /**
     * 新增友链信息
     */
//    @PreAuthorize("@ss.hasPermi('bk:friendship:add')")
    @Anonymous
    @Log(title = "友链信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BkFriendship bkFriendship)
    {
        return toAjax(bkFriendshipService.insertBkFriendship(bkFriendship));
    }

    /**
     * 修改友链信息
     */
    @PreAuthorize("@ss.hasPermi('bk:friendship:edit')")
    @Log(title = "友链信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BkFriendship bkFriendship)
    {
        return toAjax(bkFriendshipService.updateBkFriendship(bkFriendship));
    }

    /**
     * 删除友链信息
     */
    @PreAuthorize("@ss.hasPermi('bk:friendship:remove')")
    @Log(title = "友链信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{friendshipIds}")
    public AjaxResult remove(@PathVariable Long[] friendshipIds)
    {
        return toAjax(bkFriendshipService.deleteBkFriendshipByFriendshipIds(friendshipIds));
    }
}
